//
//  CustomAnnotationView.m
//  DingDongXiChe
//
//  Created by wtjr on 2018/1/5.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "CustomAnnotationView.h"

#define kCalloutWidth       200.0
#define kCalloutHeight      70.0

#define kPlaceholderImage   @"dd_home_annotationIcon"

@interface CustomAnnotationView()

@property (nonatomic, strong, readwrite) CustomCalloutView *calloutView;

@end

@implementation CustomAnnotationView


#pragma mark - BaseMethod


#pragma mark - Interface


#pragma mark - Delegate


#pragma mark - TouchEvent

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    if (self.selected == selected) return;
    if (selected) {
        if (self.calloutView == nil) {
            self.calloutView = [[CustomCalloutView alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
                                                  -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
        }
        self.image = [UIImage imageNamed:kPlaceholderImage];
        //self.calloutView.image = [UIImage imageNamed:@"dd_home_annotationIcon"];
        [self.calloutView.portraitView sd_setImageWithURL:[NSURL URLWithString:_imageUrl]
                                         placeholderImage:[UIImage imageNamed:kPlaceholderImage]
                                                  options:SDWebImageRetryFailed];
        self.calloutView.title = self.annotation.title;
        self.calloutView.subtitle = self.annotation.subtitle;
        [self addSubview:self.calloutView];
    } else {
        [self.calloutView removeFromSuperview];
        //点击回调
        if (self.clickCompleted) {
            self.clickCompleted(_model);
        }
    }
    [super setSelected:selected animated:animated];
}

#pragma mark - Setter

- (void)setImageUrl:(NSString *)imageUrl {
    _imageUrl = imageUrl;
}

- (void)setAnnotationImageUrl:(NSString *)annotationImageUrl {
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:annotationImageUrl]
                      placeholderImage:[UIImage imageNamed:kPlaceholderImage]
                               options:SDWebImageRetryFailed];
}

- (void)setModel:(ServiceModel *)model {
    _model = model;
}

#pragma mark - Getter

@end

